angular.module('app').controller('companyDetailCtrl', ['$q', '$http', '$state', '$scope', function ($q, $http, $state, $scope) {
    function ajax_comInfo(id) {
        var defer = $q.defer();
        $http({
            url: '/data/company.json',
            method: 'GET',
            params: {
                id: id
            }
        }).then(function (res) {
            $scope.companyInfo = res.data;
            defer.resolve(res.data);
        }, function (error) {
            defer.resolve(error);
        });
        return defer.promise;
    }

    function get_posType(data, id) {
        var obj = {};
        for (var key in data) {
            if (data[key].id == id) {
                obj = data[key];
            }
        }
        return obj;
    }

    function btnlistInit(skill, operate){
        $scope.btnlist = [];
        $scope.btnlist.push(skill, operate);
    }
    var comInfo = ajax_comInfo($state.params.id);
    comInfo.then(function (res) {
        var skill = get_posType(res.positionClass, "jishu");
        var operate = get_posType(res.positionClass, "yunying");
        btnlistInit(skill, operate);
        $scope.$broadcast('abc',{id:1}); //事件广播

    }, function (error) {
    });
    $scope.$on('parentEvent', function(event, data) {
        console.log(event);
        console.log(data);
    });


}]);
